package com.lagou.dao;

import com.lagou.entity.Student;
import com.lagou.util.DruidUtils;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.Connection;
import java.sql.Date;
import java.sql.SQLException;
import java.util.Arrays;

public class Dao {
    QueryRunner qr;
    Connection con ;
    public Dao(QueryRunner qr,Connection con){this.qr = qr;this.con=DruidUtils.getConnection();}
//int id, String name, String sex, Date bir
    public int insert(Object  [] params) throws SQLException{

        String sql = "insert into students values(?,?,?,?)";
        int update = qr.update(con, sql, params);
        return update;

    }
    public boolean finadAdmin(String username,String password) throws SQLException{
        String sql = "select * from admin where username = ?";
        Object[] query = qr.query(con, sql, new ArrayHandler(), username);
        if (query == null || query.length == 0 )return false;
        if (!query[2].equals(password) ) return false;
        return true;
       // System.out.println(Arrays.toString(query));


    }
    public void flash(){
        DbUtils.closeQuietly(con);
    }
}
